package nz.ac.massey.groupproject.ecs2;

import java.util.ArrayList;


/* Scans the entire pool of Entities and find matches.
 *
 * Might be used to achieve slightly higher performance, but the main purpose is to provide a
 * “likely correct answer” so we can test the correctness of cached Queries.
 */
public class ECSUncachedQuery implements ECSQueryInterface {

	private final ECSWorld            world;
	private final ECSQueryTemplate    queryTempl;


	public ECSUncachedQuery(ECSWorld world_, ECSQueryTemplate templ) {
		world = world_;
		queryTempl = templ;
	}

	public ECSUncachedQuery(ECSWorld world_, Class...         compTypes) {  this(world_, ECSQueryTemplate.get(compTypes));  }
	public ECSUncachedQuery(ECSWorld world_, ArrayList<Class> compTypes) {  this(world_, ECSQueryTemplate.get(compTypes));  }


	public final ArrayList<ECSEntity> listMatches() {
		var result = new ArrayList<ECSEntity>();

		for (var ent : world.entities)
			if (queryTempl.matchEntity(ent))
				result.add(ent);

		return result;
	}
}
